package org.batch.config.batch.listener;

import org.batch.entity.Trading;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ItemReadListener;
import org.springframework.stereotype.Component;

/**
 * CSV文件读取监听器
 *
 * @author LiKun
 * @date 2021/9/27 16:34
 */
@Component("tradingReaderListener")
public class TradingReaderListener implements ItemReadListener<Trading> {
    private static final Logger logger = LoggerFactory.getLogger(BatchListener.class);

    public TradingReaderListener() {
        logger.info("加载数据读取监听器类：TradingReaderListener");
    }

    @Override
    public void beforeRead() {
        logger.info("开始读取批处理数据");
    }

    @Override
    public void afterRead(Trading trading) {
        logger.info("读取数据内容为：{}", trading.toString());
    }

    @Override
    public void onReadError(Exception e) {
        logger.info("读取数据出错：{}", e.getMessage());
        e.printStackTrace();
    }
}
